package br.ucb.cm.main.mainview;

import br.ucb.cm.board.bean.Move;
import br.ucb.cm.board.ui.BoardPane;
import br.ucb.cm.board.ui.BoardController.ActionEnum;
import br.ucb.cm.main.ai.AIAlgorithm;
import br.ucb.cm.main.ai.AIFactory;
import br.ucb.cm.main.common.ComputerController;
import br.ucb.cm.main.common.GeneralConstants.PlayerEnum;

public class ComputerThread implements Runnable{
	private BoardPane boardPane;
	private PlayerEnum player;
	private ComputerController controller;

	public ComputerThread(BoardPane boardPane, PlayerEnum player, ComputerController controller) {
		this.boardPane = boardPane;
		this.player = player;
		this.controller = controller;
	}

	@Override
	public void run() {
		try {
			Thread.sleep(500l);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		AIAlgorithm algorithm = AIFactory.createNewAiAlgorithm();
		Move move = algorithm.doMove(boardPane.getPieceMap(), player);

		if(move != null)
			controller.doAction(ActionEnum.MOVE, move);
		else
			System.out.println("No movements!");
	}
}
